package com.study.modules.saas.controller;

import com.study.Util.CommonResponse;
import com.study.modules.saas.service.CosService;
import com.study.modules.saas.service.ImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author hupengming
 * @ClassName
 * @Date 2022-10-19 14:20
 * @Version 1.0
 */
@Slf4j
@Api(tags = "图片管理")
@RestController
@RequestMapping("/image/upload")
public class SaasCosController {

    @Autowired
    CosService cosService;

    @Autowired
    ImageService imageService;

    @ApiModelProperty("上传")
    @PostMapping
    public CommonResponse<Integer> upload(MultipartFile file) {
        return CommonResponse.success(imageService.addImage(file));
    }

    @ApiModelProperty("删除图片")
    @DeleteMapping("/{key}")
    public CommonResponse del(@PathVariable String key) {
        imageService.deleteImage(key);
        return CommonResponse.success();
    }

}
